# Makefile for compiling Nameservice

# Some paths
BASEDIR=..
UTILSDIR=$(BASEDIR)/../utils
PROTOCOLDIR=$(BASEDIR)/protocol
GIMNETAP_COMMON_LIBDIR=$(BASEDIR)/commonlib

# Some tools
CC=gcc
CFLAGS=-O2 -g3 -Wall -I. -I$(BASEDIR) -I$(PROTOCOLDIR) -I$(UTILSDIR) -I$(GIMNETAP_COMMON_LIBDIR) -DLINUX_OS -DUSE_SELECT_IO $(CE)
LD=gcc
LDFLAGS=
LIBS=-lpthread -lrt -lssl -lcrypto

# CommonLib
include $(GIMNETAP_COMMON_LIBDIR)/GIMnetAP-common.Makefile

# Base Sources
SRCSBASE= $(UTILSDIR)/ownutils.c $(UTILSDIR)/owndebug.c	$(UTILSDIR)/crc16.c \
	 $(PROTOCOLDIR)/protocolID.c $(GIMNETAP_COMMON_SRCS)

# All sources
SRCS=$(SRCSBASE)

# Construct lists of CPP and C objects
OBJS=$(SRCS:.c=.o)

# Define COMPILE and LINK commands
COMPILE=$(CC) $(CFLAGS) -c
LINK=$(LD) $(LDFLAGS) 

TARGETS=hubctrl_test \
			 fastProtocol_test

all: $(TARGETS)

####### HubCtrl testclient
HUBCTRLPROTOCOL_TEST_OBJECTS=$(OBJS) hubctrl_test.o
hubctrl_test: $(OBJS) $(HUBCTRLPROTOCOL_TEST_OBJECTS)
	@$(LINK) -o $@ $(HUBCTRLPROTOCOL_TEST_OBJECTS) $(LIBS) -lcurses
	@echo "      [LD] $@"

####### FastProtocol testclient
FASTPROTOCOL_TEST_OBJECTS=$(OBJS) fastProtocol_test.o
fastProtocol_test: $(OBJS) $(FASTPROTOCOL_TEST_OBJECTS)
	@$(LINK) -o $@ $(FASTPROTOCOL_TEST_OBJECTS) $(LIBS) -lcurses
	@echo "      [LD] $@"

clean:
	rm -f $(OBJS) *.o $(TARGETS)
	@echo "      [CLEAN]"

# Default compile rule.
%.o:	%.c
	$(COMPILE) -o $@ $<
	@echo "      [CC] $<"

.PHONY: all clean depend testclients
